package org.sang.mapper;

import org.apache.ibatis.annotations.*;
import org.sang.bean.Task;
import org.sang.enums.GenderEnum;
import org.sang.enums.StatusEnum;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface TaskMapper {
    @Insert("INSERT INTO `task` (name, content, address, memberNo) VALUES (#{name}, #{content}, #{address}, #{memberNo})")
    int addTask(Task task);

    @Select("SELECT taskNo, t.name, t.content, t.status, t.launchTime, t.expectedEndTime, t.address, t.endTime, m.memberNo, m.name memberName, m.phoneNr memberPhoneNr, v.volunteerNo, v.name volunteerName, v.phoneNr volunteerPhoneNr FROM `task` t LEFT JOIN member m on t.memberNo = m.memberNo LEFT JOIN volunteer v on t.volunteerNo = v.volunteerNo;")
    @Results({
            @Result(column = "status", property = "status", javaType = StatusEnum.class)
    })
    List<Task> getAll();

    @Delete("DELETE FROM `task` WHERE taskNo=#{taskNo};")
    int delete(int taskNo);

    @Update("UPDATE `task` SET name=#{name}, content=#{content}, address=#{address} WHERE taskNo=#{taskNo};")
    int update(Task task);

    @Update("UPDATE `task` SET expectedEndTime=#{expectedEndTime}, endTime=#{endTime} WHERE taskNo=#{taskNo};")
    int updateTime(Task task);
}
